<?php

namespace App\Admin\Controllers;

use App\Http\Controllers\Controller;
use App\Models\SStuApplyInfo;
use Encore\Admin\Controllers\HasResourceActions;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Layout\Content;
use Encore\Admin\Show;

class ApplyInfoController extends Controller {
	use HasResourceActions;

	/**
	 * Index interface.
	 *
	 * @param Content $content
	 * @return Content
	 */
	public function index(Content $content) {
		return $content
			->header('试听申请')
			->description('列表')
			->body($this->grid());
	}

	/**
	 * Show interface.
	 *
	 * @param mixed $id
	 * @param Content $content
	 * @return Content
	 */
	public function show($id, Content $content) {
		return $content
			->header('试听申请')
			->description('详情')
			->body($this->detail($id));
	}

	/**
	 * Edit interface.
	 *
	 * @param mixed $id
	 * @param Content $content
	 * @return Content
	 */
	public function edit($id, Content $content) {
		return $content
			->header('试听申请')
			->description('编辑')
			->body($this->form()->edit($id));
	}

	/**
	 * Create interface.
	 *
	 * @param Content $content
	 * @return Content
	 */
	public function create(Content $content) {
		return $content
			->header('试听申请')
			->description('新增')
			->body($this->form());
	}

	/**
	 * Make a grid builder.
	 *
	 * @return Grid
	 */
	protected function grid() {
		$grid = new Grid(new SStuApplyInfo);

		$grid->id('Id')->sortable();
		$grid->name('姓名');
		$grid->name_en('英文名');
		$grid->profession('职业');
		$grid->phone('电话');
		$grid->wx_num('微信号');
		$grid->type('课程类别');
		$grid->level('英语口语水平');
		$grid->test('是否参与过测试');
		$grid->ielts_time('预备雅思考试时间');
		$grid->toefl_time('预备托福考试时间');
		$grid->ielts_num('雅思考试分数');
		$grid->toefl_num('托福考试分数');
		$grid->ielts_aim('目标雅思分数');
		$grid->toefl_aim('目标托福分数');
		$grid->content('内容');
		$grid->hobby('爱好');
		$grid->except('想要的老师');
		$grid->times('时间段');
		$grid->created_at('提交时间')->sortable();

		$grid->actions(function ($actions) {
			$actions->disableDelete();
			$actions->disableEdit();
			// $actions->disableView();
		});
		$grid->disableCreateButton();

		return $grid;
	}

	/**
	 * Make a show builder.
	 *
	 * @param mixed $id
	 * @return Show
	 */
	protected function detail($id) {
		$show = new Show(SStuApplyInfo::findOrFail($id));

		$show->id('Id');
		$show->name('姓名');
		$show->name_en('英文名');
		$show->profession('职业');
		$show->phone('电话');
		$show->wx_num('微信号');
		$show->type('课程类别');
		$show->level('英语口语水平');
		$show->test('是否参与过测试');
		$show->ielts_time('预备雅思考试时间');
		$show->toefl_time('预备托福考试时间');
		$show->ielts_num('雅思考试分数');
		$show->toefl_num('托福考试分数');
		$show->ielts_aim('目标雅思分数');
		$show->toefl_aim('目标托福分数');
		$show->content('内容');
		$show->hobby('爱好');
		$show->except('想要的老师');
		$show->times('时间段');
		$show->created_at('提交时间');
		$show->panel()->tools(function ($tools) {
			$tools->disableEdit();
			// $tools->disableList();
			$tools->disableDelete();
		});
		return $show;
	}

	/**
	 * Make a form builder.
	 *
	 * @return Form
	 */
	protected function form() {
		$form = new Form(new SStuApplyInfo);

		$form->text('name', 'Name');
		$form->text('name_en', 'Name en');
		$form->text('profession', 'Profession');
		$form->mobile('phone', 'Phone');
		$form->text('wx_num', 'Wx num');
		$form->text('type', 'Type');
		$form->text('level', 'Level');
		$form->text('test', 'Test');
		$form->date('ielts_time', 'Ielts time')->default(date('Y-m-d'));
		$form->date('toefl_time', 'Toefl time')->default(date('Y-m-d'));
		$form->number('ielts_num', 'Ielts num');
		$form->number('toefl_num', 'Toefl num');
		$form->number('ielts_aim', 'Ielts aim');
		$form->number('toefl_aim', 'Toefl aim');
		$form->text('content', 'Content');
		$form->text('hobby', 'Hobby');
		$form->text('except', 'Except');
		$form->text('times', 'Times');
		$form->footer(function ($footer) {

			// 去掉`查看`checkbox
			$footer->disableViewCheck();

			// 去掉`继续编辑`checkbox
			$footer->disableEditingCheck();

			// 去掉`继续创建`checkbox
			$footer->disableCreatingCheck();

		});
		return $form;
	}
}
